package demo01;

public class hw35 {
    public static void main(String[] args) {
        int[] array = {2, 1, 3, 5, 4};
        int minIndex = 0;
        int maxIndex = 0;

        for (int i = 0; i < array.length; i++) {
            if (array[i] < array[minIndex]) {
                minIndex = i;
            }
        }
        for (int i = 0; i < array.length; i++) {  
        	if (array[i] > array[maxIndex]) {
                maxIndex = i;
            }
        }
        int temp = array[0];
        array[0] = array[maxIndex];
        array[maxIndex] = temp;

        temp = array[array.length - 1];
        array[array.length - 1] = array[minIndex];
        array[minIndex] = temp;

        
        for (int i = 0; i < array.length; i++ ) {
            System.out.print(array[i] + " ");
        }
    }
}
